{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from argparse import Namespace\n",
    "from data import get_cifar10_dataloader\n",
    "train_loader = get_cifar10_dataloader()\n",
    "test_loader = get_cifar10_dataloader(train=False)\n",
    "\n",
    "args = Namespace(**json.load(open(\"./ViT-B_16-224.json\", 'r')))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mmsa import build_mvit, freeze_model_but_mask, get_masks_from_mmsa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mvit = build_mvit(args)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mvit = freeze_model_but_mask(mvit).to('cuda:0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from train import train_mvit, eval_model\n",
    "\n",
    "train_mvit(args, train_loader, mvit)\n",
    "# eval_model(mvit, test_loader, 'cuda:0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "get_masks_from_mmsa(mvit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:root:**************************** start to evaluate *******************************\n",
      "Iteration: 100%|██████████| 313/313 [01:16<00:00,  4.07it/s]\n",
      "INFO:root:Accuracy: 0.963900\n"
     ]
    }
   ],
   "source": [
    "eval_model(mvit, test_loader, 'cuda:0')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "06048c3b56d35cbd1ed7beefb5bc3c0408d84ad94c3a632d81ba4d85532413e1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
